package fr.paris.lutece.plugins.xbmc.utils.dozer;

import org.dozer.Mapper;

import fr.paris.lutece.plugins.xbmc.bean.video.Video;
import fr.paris.lutece.plugins.xbmc.dto.video.VideoDTO;
import fr.paris.lutece.plugins.generic.dao.commons.ResultList;
import fr.paris.lutece.plugins.generic.utils.dozer.AbstractDozerConverter;
import fr.paris.lutece.portal.service.spring.SpringContextService;

/**
 * The Video converter between bean and DTO
 * @author jchaline
 */
public class VideoConverter extends AbstractDozerConverter<VideoDTO,Video>{

	private static final String BEAN_MAPPER = "mapper";

	private VideoConverter(){}
	
	public VideoDTO convertEntity(Video source) {
		Mapper mapper = (Mapper) SpringContextService.getBean(BEAN_MAPPER);
		return mapper.map(source, VideoDTO.class);
	}

	public ResultList<VideoDTO> convertEntities(ResultList<Video> findAll) {
		ResultList<VideoDTO> ret;
		if (findAll != null) {
			ret = new ResultList<VideoDTO>();
			for (Video video: findAll) {
				ret.add(convertEntity(video));
			}		
			ret.setTotalResult(findAll.getTotalResult());
		} else {
			ret = null;
		}

		return ret;
	}

}